package com.sky.myshop.controller;

import com.sky.myshop.services.OrderService;
import com.sky.myshop.services.ShapeEnum;
import com.sky.myshop.vo.GraphicData;
import com.sky.myshop.vo.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderCtrl {
    private static final String OK="{\"statu\":\"200\"}";

    @Autowired
    private OrderService orderService;

    @RequestMapping("/place")
    public String place(@RequestBody List<Orders> orders){
        orderService.batchInsert(orders);
        return OK;
    }

    @RequestMapping("/graphic/{shapeid}")
    public GraphicData getGraphicData(int shapeid){
        return orderService.getOrderAnalyse(shapeid==1? ShapeEnum.BAR:ShapeEnum.PIE);
    }
}
